package color.koitq.picker;

import android.app.Application;
import android.content.Context;
import android.os.Environment;

import androidx.multidex.MultiDex;

import com.hjq.permissions.XXPermissions;
import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager;
import com.quexin.pickmedialib.FileUtils;
import com.umeng.commonsdk.UMConfigure;

import org.litepal.LitePal;

import java.io.File;

import color.koitq.picker.ad.AdConfig;
import color.koitq.picker.util.RxHttpManager;

public class App extends Application {

    private static App context;

    public static App getContext() {
        return context;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        XXPermissions.setScopedStorage(true);
        LitePal.initialize(this);
        QMUISwipeBackActivityManager.init(this);
        RxHttpManager.init(this);

        //友盟预初始化
        UMConfigure.preInit(this, AdConfig.UmengId,getString(R.string.channel));
    }

    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    public static String getAlbumDir() {
        String imgDir = context.getFilesDir() + "/album/";
        File dir = new File(imgDir);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        return imgDir;
    }

    public String getImgPath() {
        String path = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/" + getText(R.string.app_name);
        System.out.println(FileUtils.createFolder(path));
        return path;
    }

    public String getVideoPath() {
        String path = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_MOVIES).getAbsolutePath() + "/" + getText(R.string.app_name);
        System.out.println(FileUtils.createFolder(path));
        return path;
    }

    public String getDownloadPath() {
        String path = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/" + getText(R.string.app_name);
        System.out.println(FileUtils.createFolder(path));
        return path;
    }

    public String getSystemScreenshotPath(int type) {
        String path = Environment.getExternalStoragePublicDirectory(
                type == 1 ? Environment.DIRECTORY_DCIM : Environment.DIRECTORY_PICTURES)
                .getAbsolutePath() + "/Screenshots";
        System.out.println("getSystemScreenshotPath: " + path);
        FileUtils.createFolder(path);
        return path;
    }
    public String getAudioPath() {
        return getExternalFilesDir("ringtones").getPath() + "/";
    }
}
